﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Data.Linq.Mapping;
using System.ComponentModel.Composition;

namespace Kooboo.Commerce.Repositories
{
    [Export(typeof(ISupportTicket))]
    partial class SupportTicket:Entity,ISupportTicket
    {
      
        SupportStatus ISupportTicket.Status
        {
            get
            {
                return (SupportStatus)this.Status;
            }
            set
            {
                this.Status = (int)value;
            }
        }

        List<ISupportReply> supportReplies;
        List<ISupportReply> ISupportTicket.SupportReplies
        {
            get
            {
                if (this.supportReplies == null)
                {
                    this.supportReplies = this.DataContext.SupportReplies
                        .Where(i => i.SupportTicketId == this.Id)
                        .Select(i => i as ISupportReply)
                        .ToList();

                }

                return this.supportReplies;
            }
            set
            {
                this.supportReplies = value;
            }
        }

        ICustomer customer;
        ICustomer ISupportTicket.Customer
        {
            get
            {
                if (this.customer == null)
                {
                    this.customer = this.DataContext.Customers
                        .Where(i => i.Id == this.CustomerId)
                        .FirstOrDefault();
                }

                return this.customer;
            }
            set
            {
                this.customer = value;

                this.CustomerId = value.Id;
                
            }
        }
    }
}
